package com.zhts.oa.common;



import java.io.Serializable;

/**
 * @author abreu
 * @date 2020/5/21 13:29
 */

public class ResultModel<T> implements Serializable {

    public static final String SUCCESS = "success";

    public static final String FAILURE = "failure";

    public static final String ERROR = "error";

    //状态码,前端用于判断状态
    private String code;

    //额外消息
    private String message;

    //若有数据, 则存储在该属性类
    private T data;

    public ResultModel(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static final <T> ResultModel<T> create(String code, String message, T data) {

        return new ResultModel(code, message, data);
    }

    public static final <T> ResultModel<T> success(String message, T data) {

        return new ResultModel<>(SUCCESS, message, data);
    }

    public static final <T> ResultModel<T> success(T data) {

        return new ResultModel(SUCCESS, null, data);
    }

    public static final ResultModel success() {

        return new ResultModel(SUCCESS, null, null);
    }

    public static final <T> ResultModel<T> failure(String message, T data) {

        return new ResultModel<>(FAILURE, message, data);
    }

    public static final <T> ResultModel<T> failure(T data) {

        return new ResultModel<>(FAILURE, null, data);
    }

    public static final <T> ResultModel<T> failure() {

        return new ResultModel<>(FAILURE, null, null);
    }

    public static final <T> ResultModel<T> error(String message, T data) {

        return new ResultModel<>(ERROR, message, data);
    }

    public static final ResultModel error(Object data) {

        return new ResultModel(ERROR, null, data);
    }

    public static final <T> ResultModel<T> error() {

        return new ResultModel<>(ERROR, null, null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
